package com.pro01.backend.service;

import com.pro01.backend.mapper.TrackerReportMapper;
import com.pro01.backend.pojo.TrackerReport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;

@Service
public class ConnectionStatusService {

    @Autowired
    private TrackerReportMapper trackerReportMapper;

    public boolean isUserOnline(Long userId) {
        TrackerReport latest = trackerReportMapper.getLatestReportByUser(userId);
        if (latest == null || "STOPPED".equals(latest.getEvent())) return false;

        long cutoffMillis = System.currentTimeMillis() - 30 * 60 * 1000L; // 30分钟
        return latest.getCreatedAt().after(new Timestamp(cutoffMillis));
    }
}

